<template>
	<view class="login__wrapper">
		<view class="login__top">
			<image class="login__top__logo" src="@/static/logo.png"></image>
			<text>项目管理</text>
		</view>

		<u-form class="login__box">
			<u-form-item>
				<u-input placeholder="请输入用户名" v-model="info.username" :clearable="false">用户名</u-input>
			</u-form-item>
			<u-form-item>
				<u-input placeholder="请输入密码" v-model="info.password" type="password" :clearable="false">密码</u-input>
			</u-form-item>
			<u-button type="primary" @click="login()">登录</u-button>
			<view class="privacy">
				<!-- <u-radio-group  v-model="privacyChecked">
					<u-radio  shape="square" label="我已阅读并同意"></u-radio>
					<text class="agreement"  @click="toPrivacyDetail">用户隐私协议</text>
				</u-radio-group> -->
				<checkbox-group @change="changecheck()">
					<checkbox :checked="privacyChecked">我已阅读并同意</checkbox>
					<text class="agreement" @click="toPrivacyDetail">用户隐私协议</text>
				</checkbox-group>
			</view>

		</u-form>

		<!-- <view class="login__bottom">
			<text>康飞恩信息技术有限公司</text>
		</view> -->
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				info: {
					username: "",
					password: ""
				},
				privacyChecked: false,

			}
		},
		onLoad() {
			const userinfo = uni.getStorageSync("userInfo");
			const token = uni.getStorageSync("token");
			if (userinfo && token) {
				uni.switchTab({
					url: "/pages/home/newIndex"
				});
			}else{
				uni.clearStorageSync()
			}
		},
		methods: {
			changecheck() {
				this.privacyChecked = !this.privacyChecked
				console.log(this.privacyChecked)
			},
			login() {
				if (this.privacyChecked != true) {
					uni.showToast({
						title: '请勾选用户隐私协议',
						icon: 'none',
						duration: 2000
					});
					return
				}
				if (this.info.username === "") {
					alert("请输入用户名")
					return
				}
				if (this.info.password === "") {
					alert("请输入密码")
					return
				} else {
					this.$store.dispatch('login/loginUp', this.info)
				}

			},
			toPrivacyDetail() {
				uni.navigateTo({
					url: "privacyAgreement"
				});
			}
		},
	}
</script>

<style lang="scss">
	.login__wrapper {
		width: 100vw;
		height: 100vh;
		position: fixed;
		overflow: hidden;

		.login__top {
			position: relative;
			width: 100vw;
			height: 400rpx;
			top: 30vw;
			text-align: center;
			display: flex;
			flex-direction: column;
		}

		.login__top__logo {
			margin-left: 300rpx;
			width: 20vw;
			height: 100rpx;
		}

		.login__box {
			position: absolute;
			bottom: 20%;

			display: flex;
			flex-direction: column;
			width: 70vw;
			padding: 0 100rpx 0 100rpx;

			.login__box__button {
				width: 100%;
				height: 80rpx;
				background-color: #5290ff;
				display: flex;
				justify-content: center;
				align-items: center;
				color: white;
				margin-top: 100rpx;
			}
		}

		// .login__bottom {
		// 	width: 100vw;
		// 	position: absolute;
		// 	bottom: 60rpx;
		// 	margin: auto;
		// 	text-align: center;
		// 	color: #9F9F9F;
		// }
		.loading {
			position: relative;
			right: 15rpx;
		}

		.privacy {
			margin-top: 30rpx;
			text-align: center;

			.agreement {
				color: #5290ff;
				margin-left: 2px;
			}
		}
	}
</style>
